define([
    'jquery',
    'underscore',
    'backbone',
    'text!template/project/project_item.html',
    'collection/project/project',
    'helper/split',
    'bootstrap'
], function(
    $,
    _,
    Backbone,
    ItemTemplate,
    ProjectCollection,
    SplitHelper,
    require
){

    var App = Backbone.View.extend({
        el: '#page-project',
        template: _.template(ItemTemplate),

        initialize: function() {
            this.render();
        },

        render: function() {
            var _this = this;
            var splitHelper = new SplitHelper();
            var splitPart = 'http://jira.vemic.com/browse/';

            var projectCollection = new ProjectCollection();
            projectCollection.fetch({
                success: function(projects) {
                    var projectsData = projects.toJSON();

                    for (var i=0; i<projectsData.length; i++) {
                        _this.$el.find('[bb-container]').append(_this.template({
                            application: projectsData[i].application_waver,
                            name: projectsData[i].name,
                            version: projectsData[i].version,
                            jira: projectsData[i].jira,
                            jira_name: splitHelper.handle(projectsData[i].jira, splitPart),
                            product: projectsData[i].product_waver,
                            interact: projectsData[i].interact,
                            interact_de: projectsData[i].interact_de_waver,
                            graphic: projectsData[i].graphic,
                            graphic_de: projectsData[i].graphic_de_waver,
                            frontend_de: projectsData[i].frontend_de_waver
                        }));
                    }
                }
            });
        }

    });

    new App();
});
